 {
sort $isid_vars 
capture drop sample
gen sample=(S_pds==1 & n_ud==1) 	

capture drop b_in_sample
bys b_id: egen b_in_sample=max(sample)


tabstat sourcing_metric_b_excl if n_b==1 & b_in_sample==1,  statistics(N mean min max sd p10 p25 median p75 p90)  columns(statistics)
/*
    variable |         N      mean       min       max        sd       p10       p25       p50       p75       p90
-------------+----------------------------------------------------------------------------------------------------
sourcing_m~l |      1311  -.413895        -1 -.0128537   .265722 -.8419847 -.5652414 -.3445214 -.2056404 -.1275578
------------------------------------------------------------------------------------------------------------------

*/
areg sourcing_metric_b_excl ln_q_b_all if n_b==1 & b_in_sample==1, abs(cohort_b)
predict residual_sourcing, resid

twoway (hist sourcing_metric_b_excl if n_b==1 & b_in_sample==1, frac   fcolor(none) lcolor(gs8) yla(,nogrid) graphregion(color(white)) ///
  xla(,nogrid) xline(-.1275578, lpattern(dash) lcolor(black)) xtitle("") xla(,nogrid) ) 
graph export "${figures}\FigureC1PanelA.pdf", replace

hist residual_sourcing if n_b==1 & b_in_sample==1, frac kdensity   fcolor(none) lcolor(gs8) yla(,nogrid) graphregion(color(white)) ///
 legend(off) xtitle("") xla(,nogrid)  kdenop(lcolor(black)) 
graph export "${figures}\FigureC1PanelB.pdf", replace
 
 }
 